﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Fireball.Windows.Forms;
using Fireball.Syntax;
using Fireball.CodeEditor.SyntaxFiles;
using DBConnectionLib;


namespace DBSourceToolsLib.SysObjects
{
    public class SOPatch : SysObject
    {
        
        public SOPatch(string strFileName, Database oDatabase)
            : base(SysObjectType.Patche, strFileName, oDatabase)
        {

        }

        public SOPatch(string strName, string strBaseDirectory, Database oDatabase)
            : base(strName, strBaseDirectory, oDatabase, SysObjectType.Patche)
        {

        }

        public SOPatch(SysObject oldSysObject, Database targetDatabase)
            :base ( oldSysObject.Name, targetDatabase.BaseDirectory, targetDatabase, SysObjectType.Patche)
        {
            this.Text = oldSysObject.Text;
            this.Text = this.Text.Replace("[" + oldSysObject.DBName + "]", "[" + targetDatabase.DatabaseName + "]");
        }

        public override void LoadScript(Database oDatabase, string outputFileName)
        {
            //throw new Exception("The method or operation is not implemented.");
        }


        #region IDisplayPanel Members

        public override System.Windows.Forms.Panel GetPanel()
        {
            Panel oPanel = new Panel();
            oPanel.Dock = DockStyle.Fill;

            CodeEditorControl codeEdit = new CodeEditorControl();
            codeEdit.Dock = DockStyle.Fill;

            CodeEditorSyntaxLoader.SetSyntax(codeEdit, SyntaxLanguage.SqlServer2K);
            codeEdit.Document.Text = this.Text;
            oPanel.Controls.Add(codeEdit);


            return oPanel;

        }

        #endregion

        public override Composite.DBComposite GetDBComposite()
        {
            return new Composite.DBComposite(this.Name, this.Name, Composite.DBCompositeType.Patch,
                new Composite.TreeNodeTag(this.m_Database.NickName,
                "File", this.FileName, this.QualifiedName));

        }
    }
}
